package com.jiyun.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.entity.Condition;
import com.jiyun.entity.Qleave;
import com.jiyun.service.QleaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Qleave)表控制层
 *
 * @author makejava
 * @since 2020-11-05 15:30:17
 */
@Controller
public class QleaveController {
    /**
     * 服务对象
     */
    @Autowired
    private QleaveService qleaveService;
    
    //登录成功以后展示所有
    @ResponseBody
    @RequestMapping("searchQleave")
    public Map<String,Object> searchQleave(
            @RequestParam(value = "page",defaultValue = "1")int pn,
            @RequestParam(value = "rows",defaultValue = "2")int ps,
            Condition condition
    ){
        PageHelper.startPage(pn,ps);
        List<Qleave> list = qleaveService.searchQleave(condition);
        PageInfo<Qleave> pg = new PageInfo<>(list);
        Map<String,Object> map = new HashMap<>();
        map.put("total",pg.getTotal());
        map.put("rows",pg.getList());
        return map;
    }
    @RequestMapping("/addQleave")
    public String addQleave(Qleave qleave, HttpServletRequest request){
        qleave.setStatus("待审批");
        qleaveService.insert(qleave);
        return "redirect:/show.jsp";
    }
    @RequestMapping("agreeById")
    public String agreeById(Integer id){
        qleaveService.agreeById(id);
        return "redirect:/show.jsp";
    }
    @RequestMapping("refuseById")
    public String refuseById(Integer id){
        qleaveService.refuseById(id);
        return "redirect:/show.jsp";
    }
    @RequestMapping("agree")
    public String agree(Integer [] ids){
        qleaveService.agree(ids);
        return "redirect:/show.jsp";
    }
    @RequestMapping("refuse")
    public String refuse(Integer [] ids){
        qleaveService.refuse(ids);
        return "redirect:/show.jsp";
    }
    @RequestMapping("deleteById")
    public String deleteById(Integer id){
        qleaveService.deleteById(id);
        return "redirect:/show.jsp";
    }
    @RequestMapping("goDelete")
    public String goDelete(Integer[] ids){
        qleaveService.delete(ids);
        return "redirect:/show.jsp";
    }

}